package com.bigfreakindeals.Activities;

import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ZoomControls;


import com.bigfreakindeals.R;
import com.bigfreakindeals.Application.ApplicationEx;
import com.bigfreakindeals.Common.Constant;
import com.bigfreakindeals.Controller.UIController;
import com.bigfreakindeals.Models.UniversityDeals;
import com.bigfreakindeals.Widgets.MapItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class BigfreakinDealsMapsActivity extends MapActivity{

	ProgressBar progressBar;

	MapView mapView;
	String startUrl;
	String company;
	String companydeals;
	
	int latitude=0;
	int longitude=0;
	byte type = 1;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		String lat = getIntent().getStringExtra(Constant.TAG_COMPANY_LATITUDE);
		String longi = getIntent().getStringExtra(Constant.TAG_COMPANY_LONGITUDE);
		company = getIntent().getStringExtra(Constant.TAG_COMPANY_NAME);
		companydeals = getIntent().getStringExtra(Constant.TAG_COMPANY_DEALTITLE);
		
		
		Log.i("","lat"+latitude+" long"+longitude+company+" "+companydeals);
		 if (lat != null && longi!=null){
			latitude = (int)(Double.parseDouble(lat)* 1000000);
			longitude = (int)(Double.parseDouble(longi)*1000000);
			
		 }
		getActivityView();

	}
	
	private void updateUniversityTheme() {
		UniversityDeals universitydeals = ApplicationEx.getInstance().myProfile.getlastSelectedSchool();

		LinearLayout headertopBG = (LinearLayout) findViewById(R.id.headerbg_top);
		LinearLayout headerbottomBG = (LinearLayout) findViewById(R.id.headerbg_bottom);
		TextView headerTitle = (TextView) findViewById(R.id.header_title);
		View header = (View) findViewById(R.id.header);
		
	
		
		if (universitydeals != null) {
			if (universitydeals.getSchoolTitle() != null) {
				headerTitle.setText(universitydeals.getSchoolTitle());
				headerTitle.setTextColor(universitydeals.color_school_font);
				headerTitle.setFocusable(true);
				headerTitle.setClickable(true);
				
			}
		if (universitydeals.color_school_bg > -1) {
			if (header != null)
					header.setBackgroundColor(universitydeals.color_school_bg + (-16777216));
			}

			if (universitydeals.getColor_titleBarBottomColor() > -1 && universitydeals.getColor_titleBarTopColor() > -1) {
				if (headerbottomBG != null) {
					headerbottomBG.setBackgroundColor(universitydeals.getColor_titleBarBottomColor() + (-16777216));
				}
				if (headertopBG != null)
					headertopBG.setBackgroundColor(universitydeals.getColor_titleBarTopColor() + (-16777216));
			}
		} // if university is not null
	}

	public void getActivityView() {
		setContentView(R.layout.activitymap);
		updateUniversityTheme();
		mapView = (MapView)findViewById(R.id.webmapview);
		mapView.setBuiltInZoomControls(true);
		
		final MapController mapController = mapView.getController();
		mapController.setZoom(10);
		
		GeoPoint point = new GeoPoint(latitude, longitude);
		List<Overlay> mapOverlays = mapView.getOverlays();
		 
		mapView.setContentDescription(company!=null?company:"merchant map");
		Drawable drawable = this.getResources().getDrawable(R.drawable.mappoint);
		
		MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable,this,company,companydeals,ApplicationEx.getInstance().mapDrawable);
		OverlayItem overlayitem = new OverlayItem(point, companydeals, company+" \n"+latitude+" "+longitude);
		itemizedoverlay.addOverlay(overlayitem);
		mapOverlays.add(itemizedoverlay);
		mapController.setCenter(point); 
		
		
	}
	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	

}